<?php

class Jf_Global {

    protected static $_globals = array(
        'throwException' => true,
        'catchException' => false,
        'autoload_started' => 0,
        'configs' => null,
        'directory' => null,
        'local_library' => null,
        'ext' => Jf_Controller_Router::DEFAULT_EXT,
        'view_ext' => 'phtml',
        'default_module' => Jf_Controller_Router::DEFAULT_MODULE,
        'default_controller' => Jf_Controller_Router::DEFAULT_CONTROLLER,
        'default_action' => Jf_Controller_Router::DEFAULT_ACTION,
        'bootstrap' => Jf_Bootstrap_Abstract::DEFAULT_BOOTSTRAP,
        'modules' => null,
        'default_route' => null
    );

    protected static $_ini = array(
        'Jf.library' => '',
        'Jf.action_prefer' => false,
        'Jf.lowcase_path' => false,
        'Jf.use_spl_autoload' => false,
        'Jf.forward_limit' => '5',
        'Jf.name_suffix' => true,
        'Jf.name_separator' => '',
        'Jf.cache_config' => false,
        'Jf.st_compatible' => false,
        'Jf.environ' => 'product',
        'Jf.use_namespace' => false
    );

    public static function iniSet($key, $value) {
        self::$_ini[$key] = $value;
    }

    public static function iniGet($key) {
        if (($iniValue = ini_get($key)) !== false) {
            if ($iniValue == '0') {
                $value = false;
            } elseif ($iniValue == '1') {
                $value = true;
            } else {
                $value = $iniValue;
            }
            self::iniSet($key, $value);
            return $value;
        } else {
            if (isset(self::$_ini[$key])) {
                return self::$_ini[$key];
            }
        }
        return null;
    }

    public static function set($key, $value) {
        self::$_globals[$key] = $value;
    }

    public static function get($key) {
        if (isset(self::$_globals[$key])) {
            return self::$_globals[$key];
        }
        return null;
    }

    public static function isAbsolutePath($path) {
        if (substr($path, 0, 1) == "/" || ((strpos($path, ":") !== false) && (strpos(PHP_OS, "WIN") !== FALSE))) {
            return true;
        } else {
            return false;
        }
    }
}